<?php
/*
 * 比较定义文件,生成新的定义文件
 * 用于旧版本和新版本中AutoCoding数据的迁移
 * @since 1.0 2014-9-3 by sutroon
 */
require 'Inc/incDbHead.php';
require 'Data/XCall_DefinedFile.php';
require 'Data/XCall_DefinedFile_New.php';
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript" src="/Public/Script/jquery-1.11.1.min.js"></script>
        <style type="text/css">
            body { font-size:12px;}
            table{width:100%; border: solid 1px #CCC; border-left:none; border-bottom: none;}
            th:first-child{width:30px;}
            .th-field {width:500px;}
            th, td { padding: 5px; border:solid 1px #CCC; border-right: none; border-top: none;}
            tr.tr-alt { background-color: #efefef;}
            a { text-decoration: none;}
            fieldset{ margin-bottom:10px; width:960px;}
            fieldset textarea { width:100%; height:600px;}
        </style>
    </head>
    <body>
        <?php
        // 全局菜单
        include 'Inc/incMenu.php';

        foreach ($DATABASE_SET_NEW as &$rTbl_New) {
            foreach ($DATABASE_SET as $rTbl) {
                if ($rTbl['TABLE_NAME'] == $rTbl_New['TABLE_NAME']) {
                    foreach ($rTbl_New['TABLE_FIELDS'] as &$rField_New) {
                        foreach ($rTbl['TABLE_FIELDS'] as $rField) {
                            if ($rField_New['Field'] == $rField['Field']) {
                                $rField_New['AutoCoding'] = array_merge($rField_New['AutoCoding'], $rField['AutoCoding']);
                            }
                        }
                    }
                }
            }
        }
        echo '<fieldset><legend>Table or List</legend><textarea>';
        echo '$DATABASE_SET = array(' . $ln;
        foreach ($DATABASE_SET_NEW as $rTable) {
            echo $tab . 'array(' . $ln;
            foreach ($rTable as $keyTable => $valTable) {
                echo $tab . $tab . "'$keyTable'=>'" . $valTable . "'," . $ln;
            }
            echo $tab . $tab . "'TABLE_FIELDS'" . ' => array(' . $ln;
            foreach ($rTable['TABLE_FIELDS'] as $rField) {
                echo $tab . $tab . $tab . 'array(';
                foreach ($rField as $keyField => $valField) {
                    if (is_array($valField)) {
                        echo "'$keyField' => array(";
                        foreach ($valField as $k => $v) {
                            echo "'$k'=>'$v', ";
                        }
                        echo '), ';
                    } else {
                        echo "'$keyField' => '$valField', ";
                    }
                }
                echo '),' . $ln;
            }
            echo $tab . $tab . '),' . $ln;
            echo $tab . '),' . $ln;
        }
        echo ');';
        echo '</textarea></fieldset>';

        // 释放资源
        unset($db);
        ?>
        <script type="text/javascript">
            // fieldset标题点击收起或展开 2014-8-22 by sutroon
            $('legend').attr('title', '点击展开或收起').click(function() {
                $(this).next().toggle();
            })
        </script>
    </body>
</html>
